/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import common.process.ExecPool;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 *
 * @author Risto Laakso <risto.laakso@gmail.com>
 */
public abstract class AbstractModel<T> {

	protected Callable<T> process;

	/**
	 * Run model, don't wait for results
	 * @return
	 */
   public Future<T> run() {
        return ExecPool.submit(process);
    }

	/**
	 * Run model, wait for results
	 * @return
	 * @throws InterruptedException
	 * @throws ExecutionException
	 */
	public T runAndGet() throws InterruptedException, ExecutionException {
        return (T) ExecPool.submit(process).get();
    }

	/**
	 * Initialize run
	 * @param id
	 * @param randSeed
	 * @throws IOException
	 */
	 public abstract void initRun(String id, long randSeed) throws IOException;


	 protected List<T> results = null;

	 public void clearResults()
	 {
		 results = new ArrayList<T>();
	 }

	 public void addResult(T result) {
		 results.add(result);
	 }

	 public abstract void parseResults();

	public AbstractModel() {
		results = new ArrayList<T>();
	}

}
